<script>
function Del_Info(str){
	var q=confirm('Bạn có chắc chắn muốn xóa hay không?');	
	if(q==true) 
		window.location=str;
	
}
</script>
<script type="text/javascript">
//<![CDATA[
  bkLib.onDomLoaded(function() {
        new nicEditor({maxHeight : 200}).panelInstance('area');
        new nicEditor({fullPanel : true,maxHeight : 200}).panelInstance('area1');
  });
  //]]>
  </script>
  <?php
$sql="SELECT substr( QUYEN,3, 1 ) as mq
FROM qldl_tai_khoan
WHERE ten_dang_nhap = '".$_SESSION['username']."'";
	$query = @mysql_query($sql,$conn);
	$row = @mysql_fetch_array($query);
	if($row['mq']==1){
	 header('Location: index.php?page=id_edit_dd&amp;id_edit_dd="'.$_GET['id_edit_dd'].'"&amp;id_ttp="'.$_GET['id_ttp'].'"'); 
	}
	else {
	echo  "<script>alert ('Bạn không có quyền truy cập trang này!')</script>"; 
	echo "<meta http-equiv='refresh' content='0;url= index.php'>";
	}
?>
  
<div class="cpanel-right-tttk">
  <div id="panel-sliders" class="pane-sliders">
    <div class="panel">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" style=" padding:10px;">
        <thead>
        <tr style=" padding-bottom:10px;">
        <th colspan="3" align="left" style="padding-bottom:10px;">QUẢN LÍ DANH MỤC ĐỊA ĐIỂM DU LỊCH</th>
        </tr> 
        </thead> 
        <tr valign="top" style="padding:5px;">
          <td width="48%"><div style=" padding:10px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
            <table width="99%" border="1" bordercolor="#666666" class="adminlist_tt">
              <thead>
                <tr>
                  <th colspan="3" align="center"> Thông tin thêm điểm du lịch</th>
                </tr>
                 <?php  
if(isset($_POST['btn_edit_dd'])){ 
	$mdd=$_GET['id_edit_dd'];
	$mttp=$_POST['chon_ttp'];
	$dd=$_POST['txt_dia_diem'];
	$tt=$_POST['area'];
	if(isset($_POST['ck_hd'])){
					$hd = $_POST['ck_hd'];}
					else $hd=0;
	
	
	if ($_FILES["file_up"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file_up"]["error"] . "<br />";
    }
  else
    { $link = $_FILES["file_up"]["name"];
    if (file_exists("dia_diem/upload/news/" . $_FILES["file_up"]["name"]))
      {
      echo $_FILES["file_up"]["name"] . " da ton tai file tren server. ";
      }
    else
      {  
      move_uploaded_file($_FILES["file_up"]["tmp_name"],
      "dia_diem/upload/news/" . $_FILES["file_up"]["name"]);	
	  
	   
      }
	  $sql2="select * from qldl_dia_diem_du_lich ";
		$query2 = @mysql_query($sql2,$conn);
		if(!$query2) echo "Query error to display.";
	else $row2 = @mysql_fetch_array($query2);
	/////////////////
if($_FILES["file_up"]["name"]==''){
		$link=$row2['HINH_ANH'];
		}
	}
	///////	
	
	$sql1 = "update qldl_dia_diem_du_lich set				
				MA_TP='$mttp',
				DIA_DIEM='$dd',
				THONG_TIN='$tt',
				DIEM_HD='$hd',
				HINH_ANH='$link'
			where MA_DIA_DIEM='$mdd'
			";
	$query1 = @mysql_query($sql1,$conn);
	/////////////////////////////
	if($query1)echo "<script>alert ('Cập nhật thông tin thành công.')</script>";	
	else echo "<script>alert ('Lỗi cập nhật thông tin!')</script>";	
	echo  "<meta http-equiv='refresh' content='0;url=index.php?page=dia_diem'>";
}
?>

              </thead>
              <tbody>
               <form action="" method="post" name="form_edit" id="form_edit" onsubmit="return input_edit();">
<?php  
	$sql="select * from qldl_dia_diem_du_lich where MA_DIA_DIEM='".$_GET['id_edit_dd']."'";
	$query = @mysql_query($sql,$conn);	
	if(!$query) echo "Query error to display.";
	else $row = @mysql_fetch_array($query);
		
  ?>
                <tr>
                  <td width="122">Mã điểm du lịch</td>
                  <td width="360" colspan="2">
                    <label for="txt_ma_dia_diem"></label>
                    <input type="text" name="txt_ma_dia_diem" id="txt_ma_dia_diem" value="<?php echo $row['MA_DIA_DIEM'];?>" readonly="readonly" />
                  </td>
                </tr>
                <tr>
                  <td>Mã tỉnh/thành phố</td>
                  <td colspan="2">
                    <label for="list_ma_thanh_pho"></label>
                    <?php
						$sql_ttp1="select * from qldl_tinh_thanh_pho where MA_TP='".$_GET['id_ttp']."'";
						$query_ttp1 = @mysql_query($sql_ttp1,$conn);	
							if(!$query_ttp1)echo "Query error to display.";
							else{
								$row_ttp1 = @mysql_fetch_array($query_ttp1);
						?>
                    <select id="chon_ttp" name="chon_ttp" value="" >
						<option value='<?php echo $row_ttp1['MA_TP'];?>' selected><?php echo $row_ttp1['THANH_PHO'];?></option>
							<?php }
							?>
							<?php 
							$sql_ttp="select * from qldl_tinh_thanh_pho order by MA_TP asc";
							$query_ttp = @mysql_query($sql_ttp,$conn);	
							if($query_ttp)
							while($row_ttp = @mysql_fetch_array($query_ttp)){
						?>  
						<option value="<?php echo $row_ttp['MA_TP'];?>"><?php echo $row_ttp['THANH_PHO'];?></option>
							<?php }?> 
					</select>
                  </td>
                </tr>
                <tr>
                  <td height="26">Điểm du lịch</td>
                  <td colspan="2">
                    <label for="txt_dia_diem"></label>
                    <input type="text" name="txt_dia_diem" id="txt_dia_diem" value="<?php echo $row['DIA_DIEM'];?>"/>
                    </td>
                </tr>
                <tr>
                  <td>Thông tin</td>
                  <td colspan="2">
                    <textarea  name="area" id="area" style="height:100px; width:100%;"><?php echo $row['THONG_TIN'];?></textarea>
                    </td>
                </tr>
                <tr>
                  <td height="17">Hình ảnh</td>
                  <td colspan="2">
                    <input type="file" name="file_up" value="<?php echo $row['HINH_ANH'];?>"/>
                  </td>
                </tr>
                <tr>
                  <td height="18" colspan="3">Hấp dẫn
                  <?php if($row['DIEM_HD']==1){ ?>
                    <input type="checkbox" checked="checked" name="ck_hd" id="ck_hd" value="1" />
                    <?php
				  }
				  elseif($row['DIEM_HD']==0){
                    ?>
                    <input type="checkbox" name="ck_hd" id="ck_hd" value="1" />
                    <?php
				  }
					?>
                    <label for="checkbox"></label></td>
                  </tr>
                <tr>
                  <td colspan="3">
                    <input type="submit" name="btn_edit_dd" id="btn_edit_dd" value="Lưu"  />
                    <input type="reset" name="Reset" id="Reset" value="Hủy"  />
                  
                   

                  </td>
                  </tr>
                  </form>
              </tbody>
            </table>
          </div></td>
          <td width="52%"><div style=" padding:10px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
            <table width="100%" border="1" bordercolor="#666666" class="adminlist_tt">
              <thead>
                <tr>
                  <th colspan="6" align="center"> Danh sách điểm du lịch</th>
                <?php include('dia_diem/del.php'); ?>
                </tr>
              </thead>
              <tbody>
               <form action="" method="post" name="form_view" id="form_view">
                <tr>
                <td width="35">Stt</td>
                  <td width="66" align="center">Mã điểm du lịch</td>
                  <td width="80" align="center">Mã thành phố</td>
                  <td width="117" align="center">Điểm du lịch</td>
                  <td width="127" align="center">Link ảnh</td>
                  <td width="84">Cập nhật</td>
                </tr>
                <?php
				$stt=0;
	$sql="select * from qldl_dia_diem_du_lich";
	$query = @mysql_query($sql,$conn);	
	if(!$query) echo "Query error to display.";
	else while($row = @mysql_fetch_array($query)){
		$stt++;
			?>	 
                <tr>
                <td><?php echo $stt;?></td>
                  <td><?php echo $row['MA_DIA_DIEM'];?></td>
                  <td><?php echo $row['MA_TP'];?></td>
                  <td><?php echo $row['DIA_DIEM'];?></td>
                  <td><?php echo $row['HINH_ANH'];?></td>
                  <td><a href="index.php?page=id_edit_dd&amp;id_edit_dd=<?php echo $row['MA_DIA_DIEM'];?>&amp;&id_ttp=<?php echo $row['MA_TP'];?>">Sửa</a> ||
                   <a onclick="Del_Info('index.php?page=dia_diem&amp;id_del_dd=<?php echo $row['MA_DIA_DIEM']; ?>&amp;id_photo_dd=<?php echo $row['HINH_ANH']; ?>');" href="#">Xóa</a></td>
                </tr>
				<?php	}
                ?>
                </form>
              </tbody>
            </table>
          </div></td>
        </tr>
      </table>
    </div>
  </div>
</div>